package com.witframework.web.tag;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class MessageTag extends TagSupport{
	@Override
	public int doStartTag() throws JspException {	
		StringBuffer html=new StringBuffer("<div id=\"actionmessage\" style=\"display:none;\" class=\"action-msg-success\" >");
		HttpServletRequest request=(HttpServletRequest)pageContext.getRequest();
		List<String> messages=(List<String>) request.getAttribute("actionMessages");
		if(null!=messages)
		for(int i=0;i<messages.size();i++){
			if(i>=1) html.append("</BR>");
			html.append(messages.get(i));			
		}
		html.append("</div>");
		request.removeAttribute("actionMessages");
		html.append("<script>try{printmessageinfo('"+request.getAttribute("messagerequestids")+"');}catch(exception){}</script>");
		JspWriter writer = pageContext.getOut();
		try {
			writer.println(html);
		} catch (IOException e) {
			throw new JspException("Print/Flush in LoadingTag tag error:" + e);
		}
		return (EVAL_BODY_INCLUDE);
	}
}